package top.shmly.universal.utils;


import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import java.util.Map;
import java.util.function.Function;

/**
 * @author : zhongxianyin
 * @E-mail : music120326@hotmail.com
 * @date : 2019/4/11 9:16
 */
@SuppressWarnings("all")
public interface HttpRequestUtil {

    <T> T get(Function<ServletRequestAttributes, T> attributesTFunction);


    /**
     * 获取header 和query参数
     *
     * @param request 请求头
     * @return
     */
    Map<String, String> getParam(HttpServletRequest request);

    /**
     * 从HttpServletRequest获取header参数
     *
     * @param request 请求头
     * @return
     */
    Map<String, String> getHeaderParam(HttpServletRequest request);

    /**
     * 从HttpServletRequest获取query参数
     *
     * @param request 请求头
     * @return
     */
    Map<String, String> getQueryParam(HttpServletRequest request);

    /**
     * 从HttpServletRequest获取body的请求数据
     *
     * @param request 请求头
     * @return
     */
    Map<String, String> getBodyParam(HttpServletRequest request);

    String getBody(HttpServletRequest request);

    /**
     * 获取请求Body
     *
     * @param request
     * @return
     */
    String getBodyString(ServletRequest request);


    /**
     * json格式转Get
     *
     * @param body 请求参数
     * @return 返回get格式
     */
    String jsonToGet(String body);
}
